package com.wangp.mywrite.inwork.sentinel._2_annotaion;

import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import org.springframework.stereotype.Component;

/***
 * @author wangpeng
 * @since 2022-03-28  15:07
 */
@Component
public class AnnotationRule {

    @PostConstruct
    private void initFlowRules() {
        List<FlowRule> rules = new ArrayList<>();

        FlowRule ruleAnnotation = new FlowRule();
        ruleAnnotation.setResource("annotationSentinel");
        ruleAnnotation.setGrade(RuleConstant.FLOW_GRADE_QPS);
        ruleAnnotation.setCount(1);
        rules.add(ruleAnnotation);
        FlowRuleManager.loadRules(rules);
    }
}
